
const { resolve } =  require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
// const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const merge = require("webpack-merge")
const CommonConfig = require("./webpack.common")

// HMR hot module replacement热模块替换 / 模块热替换
// 极大提升构建速度

module.exports = merge(CommonConfig, {
  mode: 'development',
  devServer: {
    contentBase: resolve(__dirname, 'dist'),
    compress: true, // 启动gzip压缩
    port: 8090, //端口号,
    progress: true,
    open: true, // 自动打开浏览器
    // 开启HMR功能
    hot: true,
    proxy: {} // 代理
  },
  devtool: 'scouce-map',
  module: {
    rules: [
      {
        test: /\.(js|vue)$/,
        exclude: resolve('node_modules'),
        enforce: "pre",
        use: [
          {
            loader: 'eslint-loader',
            options: {
              //eslint检查报告的格式规范
              formatter: require("eslint-friendly-formatter")
            }
          }
        ]
      }
    ]
  },
  plugins: [
    // new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      title: 'vue-project',
      favicon:resolve(__dirname, './public/favicon.ico'),
      template: resolve(__dirname, './public/index.html')
    }),
    new webpack.DefinePlugin({
      BASE_URL: JSON.stringify('/')
    }),
    new webpack.HotModuleReplacementPlugin()
  ]
})

